package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.LabelResVo;
import com.miplus.ccrm.core.controller.vo.conf.WfEditReqVo;
import com.miplus.ccrm.core.controller.vo.conf.WfReqVo;
import com.miplus.ccrm.core.controller.vo.conf.WfResVo;
import com.miplus.ccrm.core.pojo.WfWorkflow;
import com.miplus.ccrm.core.mapper.WfWorkflowMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author pc
* @description 针对表【wf_workflow】的数据库操作Service实现
* @createDate 2024-03-09 16:10:26
*/
@Service
public class WfWorkflowServiceImpl extends MPJBaseServiceImpl<WfWorkflowMapper, WfWorkflow>
    implements WfWorkflowService{

    @Override
    public IPage<WfResVo> workFlowList(WfReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                WfResVo.class,
                new MPJLambdaWrapper<WfWorkflow>()
                        .selectAll(WfWorkflow.class)
                        .like(JPubUtils.IsNotEmpty(paras.getName()),"name",paras.getName())
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),"status",paras.getStatus())
                        .orderByAsc(WfWorkflow::getWfid)
        );


    }

    @Override
    public List<LabelResVo> getWorkFlowList()
    {
        return baseMapper.getWorkFlowList();
    }

    @Override
    public CmdResVo updateWorkFlow(String $usrid,WfEditReqVo paras)
    {
        WfWorkflow def=new WfWorkflow();
        BeanUtils.copyProperties(paras,def);
        def.setMddt(new Date());
        def.setMdusr($usrid);
        int ret= baseMapper.updateById(def);
        return new CmdResVo(ret,def.getWfid().toString());
    }

    @Override
    public CmdResVo insertWorkFlow(String $usrid,WfEditReqVo paras)
    {
        WfWorkflow def=new WfWorkflow();
        BeanUtils.copyProperties(paras,def);
        def.setCrdt(new Date());
        def.setCrusr($usrid);
        def.setMddt(new Date());
        def.setMdusr($usrid);
        int ret= baseMapper.insert(def);
        return new CmdResVo(ret,def.getWfid().toString());
    }

    @Override
    public CmdResVo deleteWorkFlow(String id)
    {
        int ret= baseMapper.deleteById(JPubUtils.StringToInt(id));
        return new CmdResVo(ret,id);
    }

    @Override
    public List<LabelResVo> getNamesValuesByWfid(Integer wfid)
    {
        return baseMapper.getNamesValuesByWfid(wfid);
    }
}




